package com.newoffen.com.check;

import com.aventstack.extentreports.ExtentTest;
import com.newoffen.com.listener.ExtentTestNGITestListener;
import com.newoffen.com.method.PlatformElementMethod;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.Assert;

public class PlatformCheck extends PlatformElementMethod {
    //    public CMSCheck(WebDriver driver){
//        CMSCheck cmsCheck = PageFactory.initElements(driver,CMSCheck.class);
//    }
    public Actions action;
    ExtentTestNGITestListener el = new ExtentTestNGITestListener();
    ExtentTest log = el.getlog();

    public void cmsLogin(WebDriver driver,String username, String passwd,String code) throws Exception{
        this.waitElement(driver,input_username);
        this.sendUsername(username);
        this.sendPasswd(passwd);
        this.sendCode(code);
        this.clickBtnOK();
        log.info("检查是否登录成功");
        this.waitElement(driver,platform);
        if(!doesWebElementExist(platform)){
            Assert.fail("登录失败");
        }
        Thread.sleep(1000);
    }

    public void choice(WebDriver driver) throws Exception{
        this.clickPlat();
        log.info("检查选择平台是否成功");
        this.waitElement(driver,menu_store);
        if(!doesWebElementExist(menu_store)){
            Assert.fail("登录失败");
        }
        Thread.sleep(1000);
    }

    public void store_search(WebDriver driver,String storeName,String salesclerkName)throws Exception{
        this.storeList();
        this.waitElement(driver,input_storeName);
        this.store_search(storeName,salesclerkName);
        this.waitElement(driver,text_storeName);
        if(!doesWebElementExist(text_storeName)){
            Assert.fail("搜索数据不正确");
        }
        Thread.sleep(1000);
    }

    public void store_edit(WebDriver driver)throws Exception{
        this.update_store();
//        this.switchWindow(driver);
        this.waitElement(driver,btn_save);
        this.save_store();
        this.waitElement(driver,store_name);
        if(!doesWebElementExist(store_name)){
            Assert.fail("修改不成功");
        }
        Thread.sleep(1000);
    }

    public void settlement(WebDriver driver)throws Exception{
        this.settlement();
        this.waitElement(driver,bill_day);
        if(!doesWebElementExist(bill_day)){
            Assert.fail("查看账单失败");
        }
        Thread.sleep(1000);
    }

    public void goodsList(WebDriver driver)throws Exception{
        this.goods_List();
        this.waitElement(driver,input_goodsName);
        if(!doesWebElementExist(input_goodsName)){
            Assert.fail("查看商品列表失败");
        }
        Thread.sleep(1000);
    }

    public void goods_search(WebDriver driver,String goodsName,String goodsID,String goodsType)throws Exception{
        this.waitElement(driver,input_storeName);
        this.goods_search(goodsName,goodsID,goodsType);
        this.waitElement(driver,text_storeName);
        if(!doesWebElementExist(text_storeName)){
            Assert.fail("搜索数据不正确");
        }
        Thread.sleep(1000);
    }
    public void goods_update(WebDriver driver)throws Exception{
        this.goods_update();
        this.waitElement(driver,goodssave);
        this.goods_save();
        this.waitElement(driver,text_storeName);
        if(!doesWebElementExist(text_storeName)){
            Assert.fail("编辑商品失败");
        }
        Thread.sleep(1000);
    }
    public void orderList(WebDriver driver)throws Exception{
        this.orderList();
        this.waitElement(driver,input_searchType);
        if(!doesWebElementExist(input_searchType)){
            Assert.fail("查看快递订单列表失败");
        }
        Thread.sleep(1000);
    }
    public void order_search(WebDriver driver,String searchType,String orderNo,String payType,String paySource)throws Exception{
        this.orderSearch(searchType,orderNo,payType,paySource);
        this.waitElement(driver,text_storeName);
        if(!doesWebElementExist(text_storeName)){
            Assert.fail("快递订单搜索数据不正确");
        }
        Thread.sleep(1000);
    }

    public void rxList(WebDriver driver)throws Exception{
        this.rxList();
        this.waitElement(driver,input_rxNo);
        if(!doesWebElementExist(input_rxNo)){
            Assert.fail("查看处方审核列表失败");
        }
        Thread.sleep(1000);
    }
    public void RXSearch(WebDriver driver,String rxNo)throws Exception{
        this.RXSearch(rxNo);
        this.waitElement(driver,text_storeName);
        if(!doesWebElementExist(text_storeName)){
            Assert.fail("处方搜索数据不正确");
        }
        Thread.sleep(1000);
    }

    public void afterSaleList(WebDriver driver)throws Exception{
        this.afterSaleList();
        this.waitElement(driver,input_saleNo);
        if(!doesWebElementExist(input_saleNo)){
            Assert.fail("查看售后列表失败");
        }
        Thread.sleep(1000);
    }
    public void saleOrder_search(WebDriver driver,String searchType)throws Exception{
        this.saleOrderSearch(searchType);
        this.waitElement(driver,text_storeName);
        if(!doesWebElementExist(text_storeName)){
            Assert.fail("售后订单搜索数据不正确");
        }
        Thread.sleep(1000);
    }
    public void recipeList(WebDriver driver)throws Exception{
        this.recipeList();
        this.waitElement(driver,input_rxNo);
        if(!doesWebElementExist(input_rxNo)){
            Assert.fail("查看处方笺列表失败");
        }
        Thread.sleep(1000);
    }
    public void recipeSearch(WebDriver driver,String state)throws Exception{
        this.recipeSearch(state);
        this.waitElement(driver,input_recipeState);
        if(!doesWebElementExist(input_recipeState)){
            Assert.fail("处方搜索数据不正确");
        }
        Thread.sleep(1000);
    }
    public void reportList(WebDriver driver)throws Exception{
        this.reportList();
        this.waitElement(driver,input_reportName);
        if(!doesWebElementExist(input_reportName)){
            Assert.fail("查看体检报告列表失败");
        }
        Thread.sleep(1000);
    }
    public void reportSearch(WebDriver driver,String name)throws Exception{
        this.reportSearch(name);
        this.waitElement(driver,btn_reportDetail);
        if(!doesWebElementExist(btn_reportDetail)){
            Assert.fail("报告搜索数据不正确");
        }
        Thread.sleep(1000);
    }
    public void viewDetail(WebDriver driver)throws Exception{
        this.viewDetail();
        this.waitElement(driver,username);
        if(!doesWebElementExist(username)){
            Assert.fail("查看报告详情失败");
        }
        Thread.sleep(1000);
    }

}
